﻿using System;
using System.Windows;
using BaseControlLibrary;
using DevExpress.Xpf.Core;

namespace DevControlLibrary.Common
{
    public class XmlHelper : BaseXmlHelper
    {
        private static XmlHelper _instance;
        private XmlHelper()
        {
        }

        public static XmlHelper Instance
        {
            get { return _instance ?? (_instance = new XmlHelper()); }
        }

        public string ThemeInfo
        {
            get { return GetElement("Theme"); }
            set { SetElement("Theme", value); }
        }
        /// <summary>
        /// 给窗体设置皮肤
        /// </summary>
        /// <param name="win"></param>
        public void SetTheme(DependencyObject win)
        {
            string themeName = ThemeInfo;
            if (themeName != string.Empty)
            {
                ThemeManager.SetThemeName(win, themeName);
            }
        }

        /// <summary>
        /// 是否显示过滤窗口
        /// </summary>
        public bool IsShowAutoFilterRow
        {
            get
            {
                bool isShow = true;
                bool.TryParse(GetElement("ShowAutoFilterRow"), out isShow);
                return isShow;
            }
            set
            {
                SetElement("ShowAutoFilterRow", value.ToString());
                if (ShowAutoFilterRowAction != null)
                    ShowAutoFilterRowAction(value);
            }
        }

        public bool IsRibbonVisible
        {
            get
            {
                bool isShow = false;
                bool.TryParse(GetElement("IsRibbonVisible"), out isShow);
                return isShow;
            }
            set
            {
                SetElement("IsRibbonVisible", value.ToString());
            }
        }

        public Action<bool> ShowAutoFilterRowAction { get; set; }
    }
}
